package auth

import (
	"beluga/models"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
)

//UserLogoutController 用户注销控制器
type UserLogoutController struct {
	beego.Controller
}

//Get 方法
func (c *UserLogoutController) Get() {
	// 用户注销
	// 设置一个快速过期的 sookie，来实现注销
	//c.Ctx.SetCookie("beluga", "beluga", 5)
	o := orm.NewOrm()

	cookie := c.Ctx.GetCookie("beluga")
	QuerySession := models.Session{Value: cookie}
	err := o.Read(&QuerySession, "Value")
	beego.Informational(err)
	if err == nil {
		o.Delete(&models.Session{Id: QuerySession.Id})
		c.Ctx.SetCookie("beluga", "beluga", 1)
	}
	//c.Ctx.WriteString(cookie)
	c.Ctx.SetCookie("beluga", "beluga", 1)
	c.Data["pageName"] = "注销"
	c.TplName = "auth/logout.tpl"
}
